package com.edu.design.proxy.dynamic;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

public class MoveInvocationHandle implements InvocationHandler{
	
	private Object target;

	public MoveInvocationHandle(Object pTarget) {
		target = pTarget;
	}

	@Override
	public Object invoke(Object pProxy, Method pMethod, Object[] pArgs) throws Throwable {
		System.out.println("---开始运行---");
		long startTime = System.currentTimeMillis();
		Object result = pMethod.invoke(target, pArgs);
		long endTime = System.currentTimeMillis();
		System.out.println("---运行结束--");
		System.out.println("共用时："+(endTime-startTime)/1000);
		return result;
	}
	
	public Object getProxy(){
		Class<?> cls = target.getClass();
		return Proxy.newProxyInstance(cls.getClassLoader(), cls.getInterfaces(), this);
	}

}
